package demo.propertySupport;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

/**
 * description: <br>
 * createTime: 2021/1/13 16:57 <br>
 *
 * @author zzh
 */
public class NameListener implements PropertyChangeListener, VetoableChangeListener {

    @Override
    public void vetoableChange(PropertyChangeEvent evt)
            throws PropertyVetoException {
        // 抛异常可以使赋值失败
        if(evt.getNewValue().equals("frank"))
            throw new PropertyVetoException("新值不能是frank", evt);

        System.out.println("vetoableChange");
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if(evt.getNewValue().equals("frank"))
            throw new RuntimeException("新值不能是frank");
        System.out.println("#######proChange#######");
        System.out.println("新值:"+evt.getNewValue());
        System.out.println("旧值:"+evt.getOldValue());

    }

}
